package com.xyzwps.harbor.handler.user;

import com.xyzwps.harbor.handler.filter.AuthFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunctions;

import static com.xyzwps.harbor.handler.FiltersHelper.compose;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

@Component
public class UserRoutes {

    @Autowired
    private UserHandler user;

    @Autowired
    private AuthFilter auth;

    public void routes(RouterFunctions.Builder builder) {
        builder.nest(accept(APPLICATION_JSON), b -> b
                .POST("/pre-register", user::preRegister)
                .POST("/pre-register", user::preRegister)
                .POST("/register", user::register)
                .POST("/login", user::login)
                .GET("/profile", compose(user::profile, auth))
                .GET("/{userId}", user::getUser)
        );
    }
}
